<!-- 表格组件 -->
<script lang="tsx" setup>
import { toRaw } from "vue";

import type { TableColumnOption } from "@/components/table-widget/table-widget.vue";
import TableWidget from "@/components/table-widget/table-widget.vue";
import TableWidgetCopy from "@/components/table-widget/table-widgetcopy.vue";
import { enclosureParkBarriersRemoveByIdUsingGet,jeecgbootSysPermissionEdit } from "@/genapi/wh-yqd";

import { injectState } from "../state";

defineOptions({ name: "Sheet" });

const {
	selectedList,
	tableRef,
	detailDialogRef,
	page: { records, isLoading, execute },
} = injectState()!;

watch(records, () => tableRef.value?.table?.clearSelection());

//删除按钮
const onAudit = async (row: (typeof records.value)[0]) => {
	await ElMessageBox.confirm(`确认删除吗？`, {
		type: "info",
		title: "提示",
	});
	const res = await enclosureParkBarriersRemoveByIdUsingGet({
		params: {
			id: row.key!,
		},
	});
  console.log(res)
  console.log(row)
	await execute();
  ElMessage.success(res.message);
};

const columns: TableColumnOption<(typeof records.value)[0]>[] = [
	{
		type: "selection",
		fixed: "left",
		noExport: true,
	},
	// {
	// 	label: "ID",
	// 	width: "100",
	// 	formatter: (row) => row.index ?? "-",
	// },
	{
		label: "角色名称",
		formatter: (row) => row.title ?? "-",
	},
	{
		label: "操作",
		width: "350",
		export: false,
		fixed: "right",
		noExport: true,
		formatter(row) {
			return (
				<>
					<el-button
						size="small"
						type="primary"
						text
						onClick={() => detailDialogRef.value?.trigger("read", row)}
					>
						分配权限
					</el-button>
					<el-button
						size="small"
						type="primary"
						text
						onClick={() => detailDialogRef.value?.trigger("write", row)}
					>
						编辑
					</el-button>
					<el-button
						size="small"
						type="primary"
						text
						onClick={() => onAudit(row)}
					>
						删除
					</el-button>
				</>
			);
		},
	},
];
</script>

<template>
	<TableWidgetCopy
		fit
		ref="tableRef"
		v-loading="isLoading"
		:data="records"
		:columns="columns"
		h="100%!"
		@selection-change="(rows: any) => (selectedList = toRaw(rows))"
	/>
</template>
<style scoped lang="scss">
.el-table td.el-table__cell div {
	display: flex;
	justify-content: center !important;
}
</style>